import { IMemberParams } from "@/api/risk/types"
import { FormatMessageProps, useLocale } from "@/locales"

import { venueMap } from "../../formItems/common/venueType"
import { dataLimitedRedRes } from "."
import { EditModal } from "./components/EditModal"
const status = {
	1: "修改中",
	2: "正常",
	3: "失败"
}

const statusFn = (val: keyof typeof status) => {
	return status[val]
}
export const columnsLimitedRed = (
	formatMessage: FormatMessageProps,
	data: IMemberParams,
	dataLimitedRed: dataLimitedRedRes[],
	handleGetLimitedRed: () => Promise<void>
) => {
	const { newFormat } = useLocale()

	const getVenue = (text: string) => {
		return newFormat(venueMap.get(text) as string) as string
	}

	return [
		{
			dataIndex: "templateId",
			title: formatMessage({ id: "member.limited_red.affiliated_venue" }),
			render: (value: any, record: any) => {
				return <p>{getVenue(record.venueTypeCode)}</p>
			},
			width: 150,
			align: "center",
			key: "templateId"
		},
		{
			dataIndex: "templateName",
			title: formatMessage({ id: "member.limited_red.limited_red_template" }),
			render: (value: any, record: any) => <p>{record.templateName}</p>,
			width: 150,
			align: "center",
			key: "templateName"
		},
		{
			dataIndex: "otherRestrictions",
			title: formatMessage({ id: "member.limited_red.other_restrictions" }),
			render: (value: any, record: any) => <p>{record.otherRestrictions ? record.otherRestrictions : "-"}</p>,
			width: 150,
			align: "center",
			key: "other_restrictions"
		},
		{
			dataIndex: "status",
			title: formatMessage({ id: "member.limited_red.state" }),
			render: (value: any, record: any) => {
				const result = statusFn(record.status) || "-"
				return <p style={{ color: record.status != 2 ? "red" : "" }}>{result}</p>
			},
			width: 150,
			align: "center",
			key: "status"
		},
		{
			dataIndex: "operate",
			title: formatMessage({ id: "member.limited_red.operate" }),
			render: () => {
				return <EditModal data={data} dataLimitedRed={dataLimitedRed} refreshData={handleGetLimitedRed} />
			},
			width: 150,
			align: "center",
			key: "operate"
		}
	]
}
